import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.io.*; public class Pliiats extends Applet implements ActionListener, MouseListener, MouseMotionListener{ Button nupp=new Button(" Sisse "); Button nupp1=new Button(" Suurenda "); Button nupp2=new Button(" Vähenda "); Button nupp3=new Button(" Välja "); double x[]={0, 20, 20, 15, 5, 0}; double y[]={0, 0, 100, 110, 110, 100}; double t[]={0, 20, 20, 15, 5, 0}; double v[]={0, 0, 100, 110, 110, 100}; int x2[]={0,0,0,0,0,0}; int y2[]={0,0,0,0,0,0}; int n=6; double x1[]={5, 15, 10}; double y1[]={110, 110, 125}; double t1[]={5, 15, 10}; double v1[]={110, 110, 125}; int x3[]={0,0,0}; int y3[]={0,0,0}; int n1=3; int s=0; int pihtas=0; int i; double nurk; public Pliiats(){ addMouseListener(this); addMouseMotionListener(this); add(nupp); add(nupp3); add(nupp1); add(nupp2); nupp1.addActionListener(this); nupp3.addActionListener(this); nupp2.addActionListener(this); nupp.addActionListener(this); } public void mousePressed(MouseEvent e){ if(e.getX()t1[0] && e.getY()v1[1]){ pihtas=1; }else{pihtas=0;} } public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseMoved(MouseEvent e){} public void mouseDragged(MouseEvent e){ if(pihtas==1){ nurk=(0-(double)e.getX())/((double)e.getY()-0); nurk=Math.atan(nurk); repaint(); } } public void actionPerformed(ActionEvent e){ if (e.getSource()==nupp){ s=1; repaint(); } if (e.getSource()==nupp3){ s=0; repaint(); } if (e.getSource()==nupp2){ x[1]=x[1]-2; y[2]=y[2]-2; x[2]=x[2]-2; y[3]=y[3]-2; x[3]=x[3]-2; y[4]=y[4]-2; y[5]=y[5]-2; x1[1]=x1[1]-2; x1[2]=x1[2]-1; y1[0]=y1[0]-2; y1[1]=y1[1]-2; y1[2]=y1[2]-2; repaint(); } if (e.getSource()==nupp1){ x[1]=x[1]+2; y[2]=y[2]+2; x[2]=x[2]+2; y[3]=y[3]+2; x[3]=x[3]+2; y[4]=y[4]+2; y[5]=y[5]+2; x1[1]=x1[1]+2; x1[2]=x1[2]+1; y1[0]=y1[0]+2; y1[1]=y1[1]+2; y1[2]=y1[2]+2; repaint(); } } public void paint(Graphics g){ for(i=0; i<6; i++){ t[i]=x[i]*Math.cos(nurk)-y[i]*Math.sin(nurk); v[i]=x[i]*Math.sin(nurk)+y[i]*Math.cos(nurk); System.out.println(t[i]); } for(i=0; i<3; i++){ t1[i]=x1[i]*Math.cos(nurk)-y1[i]*Math.sin(nurk); v1[i]=x1[i]*Math.sin(nurk)+y1[i]*Math.cos(nurk); } for(i=0; i<6; i++){ x2[i]=(int)t[i]; y2[i]=(int)v[i]; } for(i=0; i<3; i++){ x3[i]=(int)t1[i]; y3[i]=(int)v1[i]; } g.setColor(Color.yellow); g.drawPolygon(x2,y2,n); g.fillPolygon(x2,y2,n); if(s==0){ g.setColor(Color.black); g.drawPolygon(x3,y3,n1); g.fillPolygon(x3,y3,n1); }else{} } public static void main(String argumendid[]){ Frame f=new Frame("Pliiats"); f.add(new Pliiats()); f.setSize(500, 500); f.setVisible(true); f.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); } } //ux=vx*cos(a)-vy*sin(a) //uy=vx*sin(a)+vy*cos(a)